local PartnerEquipRender = app.mvc.createRenderClass(...)

local colorDisable = cc.c3b(109,109,109)
--data =
function PartnerEquipRender.create(node)
    local sprite = PartnerEquipRender.extend(node or cc.CSLoader:createNode(Res.NewEquipNode))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init()
    return sprite
end


function PartnerEquipRender:init(data)
    self.super.init(self, data)
    self:setContentSize( self._ui.Panel:getContentSize() )
    self:refresh()
    
    self._ui["Panel"]:addClickEventListener(function(sender)
        self:showTips(sender)
    end)
end


function PartnerEquipRender:showTips(sender)
    local data = self._data
    if not data then
        return
    end

    local params = {}
    params.tipsType = Enums.TipsType.partnerEquip
    params.dataTemp = data
    if data:isUnlock() and not data:isDisableStrength() then
        params.partnerEquipstrengthenCallback = function(data)
            EM:notify(ViewEvent.Partner_OpenPartnerEquipStength, self)
        end
    end
    local otherParams = {}
    local size = sender:getContentSize()
    local pos = sender:convertToWorldSpace(cc.p(0,0))
    otherParams.tipPos = cc.p(pos.x, pos.y + size.height)
    otherParams.clipPos = pos
    local scalex = self:getScaleX()
    local scaley = self:getScaleY()
    otherParams.clipSize = cc.size(scalex * size.width, scaley * size.height)
    EM:notify(ViewEvent.Partner_ShowTips, params, otherParams)
end

function PartnerEquipRender:refresh()
    if not self._data then
        return
    end
    
    local data = self._data
    self._ui["Panel/grade"]:loadTexture(data:getIconBg())
    self._ui["Panel/icon"]:loadTexture(data:getIcon())
    self._ui["Panel/img_ContinueFlag"]:setVisible(false)
    self._ui["Panel/Panel_gem"]:setVisible(false)
    self._ui["Panel/Panel_wing"]:setVisible(false)
    self._ui["Panel/num"]:setString("+"..data:getStrengthenLevel())
    self._ui["Panel/selected"]:setVisible(false)

    if data:isDisableStrength() then
        self._ui["Panel/num"]:setVisible(false)
    else
        self._ui["Panel/num"]:setVisible(true)
    end

    if data:isUnlock() then
        self._ui["Panel/Panel_lock"]:setVisible(false)
        self._ui["Panel/icon"]:setEnabled(true)
        self._ui["Panel/num"]:setVisible(true)
        display.applyShaderByName(self._ui["Panel"])
    else
        self._ui["Panel/Panel_lock"]:setVisible(true)
        self._ui["Panel/icon"]:setEnabled(false)
        self._ui["Panel/num"]:setVisible(false)
        display.applyShaderByName(self._ui["Panel"], "ShaderGray")
    end
end

function PartnerEquipRender:setSelected(trueOrFalse)
    self._ui["Panel/selected"]:setVisible(trueOrFalse)
end

function PartnerEquipRender:setIndex(index)
    self._index = index
end

function PartnerEquipRender:getIndex()
    return self._index
end






return PartnerEquipRender